package com.mars.module.admin.controller;


import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import com.mars.common.enums.BusinessType;
import com.mars.common.result.R;
import com.mars.common.util.ExcelUtils;
import com.mars.module.admin.request.SysHandWritingRequest;
import io.swagger.annotations.Api;
import com.mars.framework.annotation.RateLimiter;
import com.mars.module.admin.entity.SysInfoConversion;
import com.mars.framework.annotation.Log;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import com.mars.common.response.PageInfo;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import com.mars.module.admin.service.ISysInfoConversionService;
import com.mars.module.admin.request.SysInfoConversionRequest;

import javax.servlet.http.HttpServletResponse;

/**
 * 资料转换记录控制层
 *
 * @author mars
 * @date 2024-04-08
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "资料转换记录接口管理",tags = "资料转换记录接口管理")
@RequestMapping("/admin/sysInfoConversion" )
public class SysInfoConversionController {

    private final ISysInfoConversionService iSysInfoConversionService;

    /**
     * 分页查询资料转换记录列表
     */
    @ApiOperation(value = "分页查询资料转换记录列表")
    @PostMapping("/pageList")
    public R<PageInfo<SysInfoConversion>> pageList(@RequestBody SysInfoConversionRequest sysInfoConversionRequest) {
        return R.success(iSysInfoConversionService.pageList(sysInfoConversionRequest));
    }

    /**
     * 获取资料转换记录详细信息
     */
    @ApiOperation(value = "获取资料转换记录详细信息")
    @GetMapping(value = "/query/{id}")
    public R<SysInfoConversion> detail(@PathVariable("id") Long id) {
        return R.success(iSysInfoConversionService.getById(id));
    }

    /**
     * 新增资料转换记录
     */
    @Log(title = "新增资料转换记录", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增资料转换记录")
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysInfoConversionRequest sysInfoConversionRequest) {
        iSysInfoConversionService.add(sysInfoConversionRequest);
        return R.success();
    }

    /**
     * 修改资料转换记录
     */
    @Log(title = "修改资料转换记录", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改资料转换记录")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody SysInfoConversionRequest sysInfoConversionRequest) {
        iSysInfoConversionService.update(sysInfoConversionRequest);
        return R.success();
    }

    /**
     * 删除资料转换记录
     */
    @Log(title = "删除资料转换记录", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除资料转换记录")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        iSysInfoConversionService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

    /**
    * 导出资料转换记录
    *
    * @param response response
    * @throws IOException IOException
    */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response,@RequestBody SysInfoConversionRequest sysInfoConversionRequest) throws IOException {
        List<SysInfoConversion> list = iSysInfoConversionService.list(sysInfoConversionRequest);
        ExcelUtils.exportExcel(list, SysInfoConversion.class, "资料转换记录信息", response);
    }


    @PostMapping(value = "/exportWord")
    public void exportWord(HttpServletResponse response,@RequestBody SysInfoConversionRequest request) throws IOException {
        iSysInfoConversionService.exportWord(response,request.getId() );
    }
}
